package thread.demo.synchronousQueue;

import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.TimeUnit;

public class SynchronousQueue_Offer {
  public static void main(String[] args) throws InterruptedException {
    SynchronousQueue<String> queue = new SynchronousQueue<>();
    
    new Thread(() -> {
      // 如果队列中没有消费者的话，直接返回false
      System.out.println(queue.offer("消费"));
    }).start();
    
    TimeUnit.MILLISECONDS.sleep(100);
    
    new Thread(() -> {
      try {
        System.out.println(queue.take());
      } catch (InterruptedException e) {
        throw new RuntimeException(e);
      }
    }).start();
  }
}
